package utils

import (
	"io/ioutil"
	"log"
	"os"
)

type FileHandler struct {
	Name    string
	Content string
}

func ReadFiles(files []string) chan FileHandler {
	channel := make(chan FileHandler)
	go func() {
		for _, filename := range files {

			file, err := os.Open(filename)
			if err != nil {
				log.Fatalf("cannot open %v", filename)
			}
			content, err := ioutil.ReadAll(file)
			if err != nil {
				log.Fatalf("cannot read %v", filename)
			}
			channel <- FileHandler{filename, string(content)}
		}

		close(channel)
	}()
	return channel
}
